//
//  AccountTool.m
//  Weibo
//
//  Created by Anasue on 9/14/15.
//  Copyright (c) 2015 Anasue. All rights reserved.
//

#import "AccountTool.h"
#import "Account.h"

#define AccountFilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"account.data"]

@implementation AccountTool

+ (void)save:(Account *)account
{
    //归档
    [NSKeyedArchiver archiveRootObject:account toFile:AccountFilePath];

}

+ (Account *)account
{
    //读取账号
    Account *account = [NSKeyedUnarchiver unarchiveObjectWithFile:AccountFilePath];
    
    //判断账号是否过期
    NSDate *now = [NSDate date];
    if ([now compare:account.expires_time] != NSOrderedAscending) {
        account = nil;
    }
    return account;
}


@end
